using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Management;
using System.Text;
using System.Windows.Forms;

namespace csharpsysinfo
{
    public partial class mountedFileSystemsForm : Form
    {
        string driveTypeString;
        decimal driveTypeDecimal;

        public mountedFileSystemsForm()
        {
            InitializeComponent();
        }

        private void okMfButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private string GetDriveType()
        {
            string driveTypeTransString;

            driveTypeTransString = "N/A";

            driveTypeDecimal = decimal.Parse(driveTypeString);

            if (driveTypeDecimal == 0)
            {
                driveTypeTransString = "Unknown";
            }

            if (driveTypeDecimal == 1)
            {
                driveTypeTransString = "No Root Directory";
            }

            if (driveTypeDecimal == 2)
            {
                driveTypeTransString = "Removable Disk";
            }

            if (driveTypeDecimal == 3)
            {
                driveTypeTransString = "Local Disk";
            }

            if (driveTypeDecimal == 4)
            {
                driveTypeTransString = "Network Drive";
            }

            if (driveTypeDecimal == 5)
            {
                driveTypeTransString = "Compact Disc";
            }

            if (driveTypeDecimal == 6)
            {
                driveTypeTransString = "RAM Disk";
            }



            return driveTypeTransString;

        }

        private void mountedFileSystemsForm_Load(object sender, EventArgs e)
        {
            decimal driveSizeDecimal, driveFreeSpaceDecimal, driveUsedSpaceDecimal, 
                    percentUsedDriveSpace;
            int genericCounterInteger;



            genericCounterInteger = 1;
            ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * from Win32_LogicalDisk"); //where drivetype=3");

            ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    try
                    {
                        if (genericCounterInteger == 1)
                        {
                            driveLetter0TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace0TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize0TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem0TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize0TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace0TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace0TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity0TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType0TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 2)
                        {
                            driveLetter1TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace1TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize1TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem1TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize1TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace1TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace1TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity1TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType1TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 3)
                        {
                            driveLetter2TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace2TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize2TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem2TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize2TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace2TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace2TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity2TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType2TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 4)
                        {
                            driveLetter3TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace3TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize3TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem3TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize3TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace3TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace3TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity3TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType3TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 5)
                        {
                            driveLetter4TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace4TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize4TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem4TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize4TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace4TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace4TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity4TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType4TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 6)
                        {
                            driveLetter5TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace5TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize5TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem5TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize5TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace5TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace5TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity5TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType5TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 7)
                        {
                            driveLetter6TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace6TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize6TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem6TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize6TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace6TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace6TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity6TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType6TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 8)
                        {
                            driveLetter7TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace7TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize7TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem7TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize7TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace7TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace7TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity7TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType7TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 9)
                        {
                            driveLetter8TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace8TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize8TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem8TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize8TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace8TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace8TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity8TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType8TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 10)
                        {
                            driveLetter9TextBox.Text = mob.Properties["Name"].Value.ToString();
                            driveFreeSpace9TextBox.Text = mob.Properties["FreeSpace"].Value.ToString();
                            driveSize9TextBox.Text = mob.Properties["Size"].Value.ToString();
                            fileSystem9TextBox.Text = mob.Properties["FileSystem"].Value.ToString();

                            driveSizeDecimal = decimal.Parse(driveSize9TextBox.Text);
                            driveFreeSpaceDecimal = decimal.Parse(driveFreeSpace9TextBox.Text);
                            driveUsedSpaceDecimal = driveSizeDecimal - driveFreeSpaceDecimal;
                            driveUsedSpace9TextBox.Text = driveUsedSpaceDecimal.ToString();

                            percentUsedDriveSpace = (driveUsedSpaceDecimal / driveSizeDecimal);
                            drivePercentCapacity9TextBox.Text = percentUsedDriveSpace.ToString("P");

                            driveTypeString = mob.Properties["DriveType"].Value.ToString();

                            GetDriveType();

                            driveType9TextBox.Text = GetDriveType();
                        }
                    }
                    catch
                    {
                    }
                    genericCounterInteger++;
                }


        }










    }
}